*12-09-24_loop_mi_robustness.do


clear
macro drop _all
global filetree /Users/Allan/Dropbox/!!Papers/Liberal Peace/12-02-21_ISQ_commentary/DOR_ISQ_2013_Replication/M_Rep

cd "$filetree"
use "midata"

mi xtset, clear

**check that logit runs with midyears*
sort ccode1 ccode2 year
global controls lncprt mjpw contigl lndist numstate

gen specification="NA"
gen specnumber=.
gen n=.
gen DmlCoefficient=.
gen DmlSE=.
gen CIElCoefficient=.
gen CIElSE=.
gen Dmlpvalues=.
gen CIElpvalues=.

sum _1_lnlifepenl, d
local p75=r(p75)
mi passive: generate lnlifepenlc=lnlifepenl-`p75'
mi passive: generate dmllnlifepenlc=dml*lnlifepenlc

***Code just to see if things are running
*mi estimate, dots: logit fmidonsl lnlifedeerl dml $controls fmidyears*, cl(dyadid) 
*logit midonsl _1_lnlifedeerl dml $controls	 midyears*, cl(dyadid) 
*logit midonsl _2_lnlifedeerl dml $controls	 midyears*, cl(dyadid) 
*logit fmidonsl _3_lnlifedeerl dml $controls	 fmidyears*, cl(dyadid) nolog
*****

sort ccode1 ccode2 year

local j=0

**M2 m.i. with 4 dependent variables x interaction = 8 models
local j=`j'+1
local spec`j' "M"
local covars`j' "midonsl CIEl  dml 					   $controls midyears*"


local j=`j'+1
local spec`j' "OM"
local covars`j' "midongl CIEl  dml 					   $controls midyears*"


local j=`j'+1
local spec`j' "FM"
local covars`j' "fmidonsl CIEl  dml 					   $controls fmidyears*"


local j=`j'+1
local spec`j' "FOM"
local covars`j' "fmidongl CIEl  dml 					   $controls fmidyears*"

local j=`j'+1
local spec`j' "IM"
local covars`j' "midonsl CIElc  dml dmlCIElc 					   $controls midyears*"


local j=`j'+1
local spec`j' "OIM"
local covars`j' "midongl CIElc  dml 	 dmlCIElc 				   $controls midyears*"


local j=`j'+1
local spec`j' "FIM"
local covars`j' "fmidonsl CIElc  dml 		 dmlCIElc 			   $controls fmidyears*"


local j=`j'+1
local spec`j' "FOIM"
local covars`j' "fmidongl CIElc  dml  	dmlCIElc 				   $controls fmidyears*"



**M2 m.i. with DemocracyHigh with 4 dependent variables x interaction = 8 models


**M2 with 4 dependent variables x interaction = 8 models
local j=`j'+1
local spec`j' "DM"
local covars`j' "midonsl CIEl  dml  dmh 					   $controls midyears*"


local j=`j'+1
local spec`j' "ODM"
local covars`j' "midongl CIEl  dml  dmh 					   $controls midyears*"


local j=`j'+1
local spec`j' "FDM"
local covars`j' "fmidonsl CIEl  dml  dmh 					   $controls fmidyears*"


local j=`j'+1
local spec`j' "FODM"
local covars`j'  "fmidongl CIEl  dml  dmh					   $controls fmidyears*"


local j=`j'+1
local spec`j'  "IDM"
local covars`j'  "midonsl CIElc  dml dmlCIElc 	 dmh 				   $controls midyears*"


local j=`j'+1
local spec`j'  "OIDM"
local covars`j'  "midongl CIElc  dml 	 dmlCIElc 	 dmh 			   $controls midyears*"


local j=`j'+1
local spec`j'  "FIDM"
local covars`j'  "fmidonsl CIElc  dml 		 dmlCIElc 	 dmh 		   $controls fmidyears*"


local j=`j'+1
local spec`j'  "FOIDM"
local covars`j' "fmidongl CIElc  dml  	dmlCIElc 	 dmh 			   $controls fmidyears*"




****With other measures of life insurance expenditures


**M2 m.i. with 4 dependent variables x interaction = 8 models
local j=`j'+1
local spec`j' "L"
local covars`j' "midonsl lnlifepenlc  dml 					   $controls midyears*"


local j=`j'+1
local spec`j' "OL"
local covars`j' "midongl lnlifepenlc  dml 					   $controls midyears*"


local j=`j'+1
local spec`j' "FL"
local covars`j' "fmidonsl lnlifepenlc  dml 					   $controls fmidyears*"


local j=`j'+1
local spec`j' "FOL"
local covars`j' "fmidongl lnlifepenlc  dml 					   $controls fmidyears*"

local j=`j'+1
local spec`j' "IL"
local covars`j' "midonsl lnlifepenlc  dml dmllnlifepenlc 					   $controls midyears*"


local j=`j'+1
local spec`j' "OIL"
local covars`j' "midongl lnlifepenlc  dml 	 dmllnlifepenlc 				   $controls midyears*"


local j=`j'+1
local spec`j' "FIL"
local covars`j' "fmidonsl lnlifepenlc  dml 		 dmllnlifepenlc 			   $controls fmidyears*"


local j=`j'+1
local spec`j' "FOIL"
local covars`j' "fmidongl lnlifepenlc  dml  	dmllnlifepenlc 				   $controls fmidyears*"



**M2 m.i. with DemocracyHigh with 4 dependent variables x interaction = 8 models

local j=`j'+1
local spec`j' "DL"
local covars`j' "midonsl lnlifepenlc  dml  dmh 					   $controls midyears*"


local j=`j'+1
local spec`j' "ODL"
local covars`j' "midongl lnlifepenlc  dml  dmh 					   $controls midyears*"


local j=`j'+1
local spec`j' "FDL"
local covars`j' "fmidonsl lnlifepenlc  dml  dmh 					   $controls fmidyears*"


local j=`j'+1
local spec`j' "FODL"
local covars`j'  "fmidongl lnlifepenlc  dml  dmh					   $controls fmidyears*"


local j=`j'+1
local spec`j'  "IDL"
local covars`j'  "midonsl lnlifepenlc  dml dmllnlifepenlc 	 dmh 				   $controls midyears*"


local j=`j'+1
local spec`j'  "OIDL"
local covars`j'  "midongl lnlifepenlc  dml 	 dmllnlifepenlc 	 dmh 			   $controls midyears*"


local j=`j'+1
local spec`j'  "FIDL"
local covars`j'  "fmidonsl lnlifepenlc  dml 		 dmllnlifepenlc 	 dmh 		   $controls fmidyears*"


local j=`j'+1
local spec`j'  "FOIDL"
local covars`j' "fmidongl lnlifepenlc  dml  	dmllnlifepenlc 	 dmh 			   $controls fmidyears*"


sort ccode1 ccode2 year

**Estimating Models, Saving Values
forvalues k=1(1)`j' {
replace specification="`spec`k''" if _n==`k'
mi estimate, dots: logit `covars`k'', cl(dyadid) nolog
replace n= e(N)   if _n==`k'
mat A=e(b_mi)
mat V=e(V_mi)
replace specnumber=`k' if _n==`k'
replace DmlCoefficient=A[1,2] if _n==`k'
replace DmlSE=(V[2,2])^(1/2) if _n==`k'
replace CIElCoefficient=A[1,1] if _n==`k'
replace CIElSE=(V[1,1])^(1/2) if _n==`k'
}





order specification specnumber DmlCoefficient DmlSE Dmlpvalues CIElCoefficient CIElSE CIElpvalues
replace Dmlpvalues=2*normal(-abs(DmlCoefficient/DmlSE))
replace CIElpvalues=2*normal(-abs(CIElCoefficient/CIElSE))
keep specification specnumber DmlCoefficient DmlSE Dmlpvalues CIElCoefficient CIElSE CIElpvalues
drop if specnumber==.


saveold "robustnessMdml.dta", replace

